package com.csii.modules.online.cgform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import java.lang.invoke.SerializedLambda;
import java.util.Iterator;
import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.csii.core.util.oConvertUtils;
import com.csii.modules.online.cgform.entity.OnlCgformField;
import com.csii.modules.online.cgform.entity.OnlCgformHead;
import com.csii.modules.online.cgform.mapper.OnlCgformFieldMapper;
import com.csii.modules.online.cgform.mapper.OnlCgformHeadMapper;
import com.csii.modules.online.cgform.service.IOnlineBaseAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("onlineBaseAPI")
public class OnlineBaseAPIImpl implements IOnlineBaseAPI {
   @Autowired
   private OnlCgformHeadMapper onlCgformHeadMapper;
   @Autowired
   private OnlCgformFieldMapper onlCgformFieldMapper;

   public String getOnlineErpCode(String code, String tableType) {
      if ("3".equals(tableType)) {
         String var3 = code.substring(1);
         OnlCgformHead var4 = (OnlCgformHead)this.onlCgformHeadMapper.selectById(var3);
         if (var4 != null && var4.getTableType() == 3) {
            LambdaQueryWrapper var5 = Wrappers.lambdaQuery(OnlCgformField.class).eq(OnlCgformField::getCgformHeadId, var3);
            List var6 = this.onlCgformFieldMapper.selectList(var5);
            if (var6 != null && var6.size() > 0) {
               String var7 = null;
               Iterator var8 = var6.iterator();

               while(var8.hasNext()) {
                  OnlCgformField var9 = (OnlCgformField)var8.next();
                  if (oConvertUtils.isNotEmpty(var9.getMainTable())) {
                     var7 = var9.getMainTable();
                     break;
                  }
               }

               LambdaQueryWrapper var10 = Wrappers.lambdaQuery(OnlCgformHead.class).eq(OnlCgformHead::getTableName, var7);
               OnlCgformHead var11 = (OnlCgformHead)this.onlCgformHeadMapper.selectOne(var10);
               if (var11 != null && "erp".equals(var11.getThemeTemplate())) {
                  code = "/" + var11.getId();
               }
            }
         }
      }

      return code;
   }
}
